package com.cyk.controller;

import com.cyk.entity.User;
import com.cyk.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User user(@PathVariable("id") Long id) {
        return userService.queryById(id);
    }

    @PostMapping
    public String add(User user) {
        userService.insert(user);
        return "ok";
    }

    @DeleteMapping("/{id}")
    public String delete(@PathVariable("id") Long id) {
        userService.deleteById(id);
        return "ok";
    }

    @PutMapping
    public User update(@RequestBody User user) {
        return userService.update(user);
    }

}
